﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.classesBasicas.equipamento;
using Biblioteca.fachada;

namespace Desktop.views.cruds.crudsEquipamento.crudColete
{
    public partial class AlterarRemoverColete : Form
    {
        private Colete colete;
        private MenuColete menucolete;
        Fachada fachada = new Fachada();

        public AlterarRemoverColete(MenuColete menucolete, Colete colete)
        {
            // TODO: Complete member initialization
            this.colete = colete;
            this.menucolete = menucolete;
            menucolete.Hide();

            InitializeComponent();

            inicializaTextsBoxs();
        }

        private void buttonAlterar_Click(object sender, EventArgs e)
        {
            try{
            this.colete = alteraTextsBoxs();

            fachada.alterarColete(this.colete);

            menucolete.carregarGridViewColete();
            menucolete.Show();
            this.Dispose();
            MessageBox.Show("Alterado com sucesso");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void buttonRemover_Click(object sender, EventArgs e)
        {
            try{
            
            fachada.removerColete(this.colete);

            menucolete.carregarGridViewColete();
            menucolete.Show();
            this.Dispose();
            MessageBox.Show("Removido com sucesso");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void buttonCancelar_Click(object sender, EventArgs e)
        {
            menucolete.Show();
            this.Dispose();
        }

        private void AlterarRemoverColete_FormClosed(object sender, FormClosedEventArgs e)
        {
            menucolete.Show();
            this.Dispose();
        }

        
        private void inicializaTextsBoxs()
        {
            this.labelIdValor.Text = this.colete.Id;
            this.textBoxNome.Text = this.colete.Nome;
            this.textBoxTipo.Text = this.colete.Tipo;
            this.textBoxMarca.Text = this.colete.Marca;
            this.textBoxValor.Text = this.colete.Valor;

        }

        private Colete alteraTextsBoxs()
        {
            this.colete.Id = this.labelIdValor.Text;
            this.colete.Nome = this.textBoxNome.Text;
            this.colete.Tipo = this.textBoxTipo.Text;
            this.colete.Marca = this.textBoxMarca.Text;
            this.colete.Valor = this.textBoxValor.Text;

            return colete;
        }


        //Validação individual
        public void validacaoTextBox()
        {
            //if (textBoxNome.Text == "")
            //{
            //    textBoxNome.Focus();

            //    MessageBox.Show("Por favor, informar o nome do cliente:", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            //else if (maskedTextBoxRg.Text =="") 
            //{
            //    maskedTextBoxRg.Focus();

            //    MessageBox.Show("Tem certeza que quer cadastrar cliente sem Rg?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            //    //if MessageBoxButtons.YesNo == true 

            //}            
        }



        //Metódo cor entrada TextBox
        private void CorEntrada(TextBox tb)
        {
            tb.BackColor = Color.LightBlue;
        }
        //Metódo cor saída TextBox
        private void CorSaida(TextBox tb)
        {
            tb.BackColor = Color.White;
        }


        //Evento TextBox Enter
        private void textBoxNome_Enter(object sender, EventArgs e)
        {
            CorEntrada((TextBox)sender);
        }
        //Evento TextBox Leave
        private void textBoxNome_Leave(object sender, EventArgs e)
        {
            CorSaida((TextBox)sender);
        }
        
        

             
    }
}
